// 封装本地存储的操作

import { Token } from '@/types/data'

// 消除   魔法字符串
const TOKEN_KEY = 'itcast_geek_pc'

export function getToken ():Token {
  return JSON.parse(localStorage.getItem(TOKEN_KEY) || '{}')
}

export function setToken (token:Token) {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(token))
}

export function removeToken () {
  localStorage.removeItem(TOKEN_KEY)
}

export function hasToken () {
  return !!getToken().token
}
